package com.winning.util.excelutil.common.exception;


import com.winning.util.excelutil.common.dto.BaseProtocolOut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class BaseExceptionHandler {
	private Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * 处理自定义异常
	 */
	@ExceptionHandler(BaseException.class)
	public BaseProtocolOut handleException(BaseException e){
		BaseProtocolOut re = BaseProtocolOut.error(e.getCode(),e.message());
        logger.error("BaseException:errorCode="+e.getCode()+"errorMsg="+e.getMessage());
		return re;
	}

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public BaseProtocolOut handleException(Exception e){
		BaseProtocolOut re = BaseProtocolOut.error(500,e.getMessage());
		logger.error("ProtocolException:errorCode="+500+"errorMsg="+e.getMessage());
		return re;
	}

}
